/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.lswms.controller;

import com.lswms.annotation.Login;
import com.lswms.annotation.LoginUser;
import com.lswms.common.utils.Result;
import com.lswms.common.validator.ValidatorUtils;
import com.lswms.dto.YnBankcardDTO;
import com.lswms.dto.vo.req.BankcardReq;
import com.lswms.dto.vo.req.UnBankcardReq;
import com.lswms.entity.YnUserEntity;
import com.lswms.service.YnBankcardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.annotations.ApiIgnore;

import com.alibaba.fastjson.JSON;


/**
 * 绑卡接口
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/api/bankcard")
@Api(tags="绑卡接口")
@Slf4j
public class YnBankcardController {
	
	@Autowired
	private YnBankcardService ynBankcardService;
	
    /**
     * 绑卡列表
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("bankcardList")
    @ApiOperation("绑卡列表")
    @Login
    public Result<List<YnBankcardDTO>> bankcardList(@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
        return new Result<List<YnBankcardDTO>>().ok(ynBankcardService.bankcardList(ynuser));
    }
    
    /**
     * 绑卡
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("bankcard")
    @ApiOperation("绑卡")
    @Login
    public Result<Object> bankcard(@RequestBody BankcardReq dto,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	log.info("绑卡，参数：{}",JSON.toJSONString(dto));
        //表单校验
        ValidatorUtils.validateEntity(dto);
        ynBankcardService.bankcard(dto, ynuser);
        return new Result<Object>();
    }
    /**
     * 解绑
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("unBankcard")
    @ApiOperation("解绑")
    @Login
    public Result<Object> unBankcard(@RequestBody UnBankcardReq dto,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	log.info("解绑，参数：{}",JSON.toJSONString(dto));
        //表单校验
        ValidatorUtils.validateEntity(dto);
        ynBankcardService.unbankcard(dto, ynuser);
        return new Result<Object>();
    }
}